#ifdef GL_ES
precision highp float;
#endif

uniform sampler2D uSampler;

uniform vec4 uMatSpecular;
uniform vec3 uAmbLightColor;
uniform vec3 uDirLightDiffColor;
uniform vec3 uDirLightSpecColor;
uniform vec3 uDirLightVect;

varying vec2 vTextureCoord;
varying vec4 vCameraSpacePos;
varying vec4 vCameraSpaceNorm;

void main(void) {
    vec3 eyeVect = normalize(-vCameraSpacePos.xyz);
    vec3 reflectVect = reflect(uDirLightVect, vCameraSpaceNorm.xyz);

    float specWeight = pow(max(dot(reflectVect, eyeVect),0.0),uMatSpecular.a);
    float diffWeight = max(dot(vCameraSpaceNorm.xyz, -uDirLightVect), 0.0);
    vec3 lightWeight = uAmbLightColor + uDirLightDiffColor * diffWeight;
    vec3 lightSpecularWeight = uDirLightSpecColor * specWeight;
    
    vec4 texColor = texture2D(uSampler, vTextureCoord);
    gl_FragColor = vec4(texColor.rgb * lightWeight 
                        + uMatSpecular.rgb * lightSpecularWeight, texColor.a);

}
